package com.zxl.admin.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zxl.common.mapper.SysApiMapper;
import com.zxl.common.mapper.SysUserRoleMapper;
import com.zxl.common.model.pojo.SysApi;
import com.zxl.common.model.pojo.SysUserRole;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zxw
 * @date 2023/4/7
 */
@Service
public class ApiService {

    @Resource
    private SysUserRoleMapper sysUserRoleMapper;
    @Resource
    private SysApiMapper sysApiMapper;

    public List<SysApi> getMenu(Integer userId) {
        SysUserRole sysUserRole = sysUserRoleMapper.selectOne(new QueryWrapper<SysUserRole>()
                .eq("user_id", userId));
        if (sysUserRole == null){
            return new ArrayList();
        }
        if (sysUserRole.getRoleId().equals(1)){
            List<SysApi> sysApiEntities = sysApiMapper.selectList(
                    new QueryWrapper<SysApi>().select("url"));
            return sysApiEntities;
        }

        return sysApiMapper.getUserUrl(sysUserRole.getRoleId());

    }
}
